﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace PaulBeck.Timesheet.WebParts.BookTimeNew
{
    [ToolboxItemAttribute(false)]
    public class BookTimeNew : WebPart
    {
        Literal lit;

        int WeekId = 0;
        int UserId = 0;

        protected override void CreateChildControls()
        {
            lit = new Literal();
            if ((WeekId == 0) || (UserId == 0)) {     lit.Text = string.Format("<div class=\"ts-new-time-div\"><a class=\"ts-new-time-link\">New Task</a></div>");     }
            else      {      lit.Text = string.Format("<div class=\"ts-new-time-div\"><a href=\"javascript:OpenDialogAdr('{0}?IsDlg=1&weekid={1}&userid={2}')\" class=\"ts-new-time-link\">New Task</a></div>", CommonWFE.GetTimesheetEditUrl(), WeekId.ToString(), UserId.ToString());   }
            this.Controls.Add(lit);
        }

        [ConnectionConsumer("WeekIdConsumer", "WeekIdConsumer")]
        public void ReceiveProviderWeek(BOL.Interface.IWeekId p)
        {
            WeekId = p.GetWeekId;
        }

        [ConnectionConsumer("ResourceIdConsumer", "ResourceIdConsumer")]
        public void ReceiveProviderResource(BOL.Interface.IResource p)
        {
            UserId = p.GetResourceId;
        }

    }
}
